//
//  BaseViewController.m
//  FreeTravel
//
//  Created by 徐康 on 16/8/26.
//  Copyright © 2016年 KX. All rights reserved.
//
#import <IQKeyboardManager.h>
#import "BaseViewController.h"
#import "FreeTravelMacro.h"
@interface BaseViewController ()

@end

@implementation BaseViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
      [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    self.view.backgroundColor = [UIColor whiteColor];
//    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.navigationController.navigationBar setBarTintColor:COLORFORFREETRAVEL];
    [self.navigationController.navigationBar setTranslucent:NO];
}
// 缓存
- (void)SaveData:(id)data Name:(NSString *)name{
    
    NSFileManager *manager = [NSFileManager defaultManager];
    
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/MyCache"];
    
    [manager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
    
    NSString *filePath = [NSString stringWithFormat:@"%@.plist",name];
    
    //拼接出缓存路径
    NSString *cachePath = [path stringByAppendingPathComponent:filePath];
    
    //归档
    [NSKeyedArchiver archiveRootObject:data toFile:cachePath];
    
    
    
}
// 读取缓存
- (NSArray *)LoadDataWithPath:(NSString *)name{
    
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/MyCache"];
    
    NSString *filePath = [NSString stringWithFormat:@"%@.plist",name];
    
    NSString *cachePath = [path stringByAppendingPathComponent:filePath];
    //返归档
    NSArray *cacheArr = [NSKeyedUnarchiver unarchiveObjectWithFile:cachePath];
    
    return cacheArr;
    
    
    
}

- (NSDictionary *)LoadDicDataWithPath:(NSString *)name{
    
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/MyCache"];
    
    NSString *filePath = [NSString stringWithFormat:@"%@.plist",name];
    
    NSString *cachePath = [path stringByAppendingPathComponent:filePath];
    
    NSDictionary *cacheDic = [NSKeyedUnarchiver unarchiveObjectWithFile:cachePath];
    
    return cacheDic;
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
